import { usePermissionStoreHook } from "/@/store/modules/permission";
import { Directive } from "vue";

export const auth: Directive = {
  mounted(el, binding) {
    const { value } = binding;
    if (value) {
      const authRoles = value;
      const authList = usePermissionStoreHook().buttonAuth;
      const hasAuth = (authList && authList.includes(authRoles)) ?? false;
      if (hasAuth) {
        el.style.opacity = 0;
        el.style.visibility = "hidden";
      }
    } else {
      throw new Error("need roles! Like v-auth=\"['admin','test']\"");
    }
  }
};
